package com.wn.base;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @FileName: ThreadDemo
 * @Description: TODO
 * @Author: MaWenHao
 * @Created: 2020/7/6 - 14:50
 * @Version: V1.0
 * @Company: 东方微银科技（北京）有限公司
 */
public class ThreadDemo {

    public static void main(String[] args) {
        CallableOne callableOne = new CallableOne();
        FutureTask<String> futureTask = new FutureTask<>(callableOne);

        Thread thread = new Thread(futureTask);
        thread.start();

        try {
            System.out.println(futureTask.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        
    }

}

class CallableOne implements Callable<String> {

    @Override
    public String call() throws Exception {
        System.out.println(Thread.currentThread().getName() + ",线程被执行");
        return "success";
    }
}
